package top.houry.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import top.houry.redis.config.MyARedisChannelListener;
import top.houry.redis.config.MyBRedisChannelListener;

/**
 * @Desc
 * @Author houruiyang
 * @Date 2023/2/22
 **/
@RestController
public class AddSubTestController {

    @Autowired
    private RedisMessageListenerContainer redisMessageListenerContainer;

    @GetMapping("add")
    public void add(@RequestParam(value = "topic") String topic) {
        if ("a".equals(topic)) {
            redisMessageListenerContainer.addMessageListener(new MessageListenerAdapter(new MyARedisChannelListener()), new PatternTopic(topic));
        } else {
            redisMessageListenerContainer.addMessageListener(new MessageListenerAdapter(new MyARedisChannelListener()), new PatternTopic(topic));
        }

    }


}
